<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:th="http://www.thymeleaf.org"
    
       >
         <!-- xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" -->
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>排班规则-列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/bootstraptable/bootstrap-table.min.css">
    <link rel="stylesheet" href="/plugins/bootstrapValidator/css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="/css/font-awesome.css">
    <link rel="stylesheet" href="/plugins/select2/css/select2.min.css" />
    <link rel="stylesheet" href="/plugins/select2/css/select2-bootstrap.min.css" />
    <style>
	.table-hover>tbody>tr:hover {
		background-color: #C6E2FF
		}
	</style>
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content ">
        <div class="col-sm-12">
            <div class="ibox">
			  	<div class="ibox-body">
			  	    <div id="exampleToolbar">
                        <div class="form-inline">
                            <div class="form-group">
                            		<select id="ruleType" class="form-control" >
                            			<option value=>--规则类别--</option>
									  	<option value="Hard" >硬规则</option>
									  	<option value="Waring" >告警规则</option>
									  	<option value="Soft" >软规则</option>
                            		</select>
                                    <input id="ruleCode" type="text" class="table-tool-btn form-control" placeholder="规则编码"/>
                                    <input id="ruleContent" type="text" class="table-tool-btn form-control" placeholder="规则说明"/>
                                <shiro:hasPermission1 name="CAS:assignmentRule:add">
                                    <!-- <button type="button" onclick="add()" class="btn btn-sm btn-primary" data-toggle="tooltip" title="添加">
                                        <i class="fa fa-plus" aria-hidden="true"></i>&nbsp;添加
                                    </button> -->
                                </shiro:hasPermission1>
                                <button type="button" onclick="reload()" class="btn btn-sm btn-success " data-toggle="tooltip" title="刷新">
                                    <i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;刷新
                                </button>
                            </div>
                        </div>
			  		</div>
			  		<table id="exampleTable" data-classes="table table-hover table-condensed">
                        <thead>
                            <tr>
                            </tr>
                        </thead>
                    </table>
			  	</div>
			</div>
		</div>
</div>
<script type="text/javascript">
    var p_delete = 'hidden';
    var p_edit = 'hidden';
</script>
<shiro:hasPermission1 name="CAS:assignmentRule:delete">
<script type="text/javascript">
    p_delete = '';
</script>
</shiro:hasPermission1>
<shiro:hasPermission1 name="CAS:assignmentRule:edit">
<script type="text/javascript">
    p_edit = '';
</script>
</shiro:hasPermission1>

    <script src="/js/jquery.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="/plugins/bootstraptable/bootstrap-table.min.js"></script>
    <script src="/plugins/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="/plugins/bootstrapValidator/js/bootstrapValidator.min.js"></script>
    <script src="/plugins/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="/plugins/layer/layer.js"></script>
    <script src="/plugins/select2/js/select2.full.min.js"></script>

    <!-- 自定义js -->
    <script>
        var prefix = "/assignmentRule";
        $(function () {
		
            load();
            
            //自动刷新绑定
            $("#ruleCode,#ruleContent").keydown(function(e) { 
		        if (e.keyCode == 13) { 
		               reload();
		        } 
   			}); 
   			
   			$("#ruleType").on("change", function(e) { 
   				reload();
        	});
        
        });

        function load() {
	        $('#exampleTable').bootstrapTable(
					    {
						    method : 'post',
						    url : prefix + "/list",
						    iconSize : 'outline',
						    toolbar : '#exampleToolbar',
                            striped : true,
                            dataType : "json",
                            pagination : true,
                            clickToSelect : true,
                            pageSize : 10,
                            pageNumber : 1,
                            showColumns : false,
                            sidePagination : "client",
                            contentType : "application/x-www-form-urlencoded",
                            queryParams : function(params) {
                                return {
                                	ruleCode : $('#ruleCode').val(),
                                	ruleContent : $('#ruleContent').val(),
                                	ruleType : $('#ruleType').val()
                                };
                            },
                            onClickRow: function (row,$element) {
						        	$element.addClass('info').siblings().removeClass('info').end();
						    },
                            columns : [
                                    {
                                        field : 'idx',
                                        radio : true
                                    },
                                    {
                                        title : '序号' ,
                                        formatter : function(value,row,index){
                                        	return index+1;
                                        }
                                    },
                                    {
                                        field : 'dutyCode',
                                        title : '部门' ,
                                        formatter : function(value,row,index){
                                        	if(row.dutyCode == 'F'){
                                        		return '飞行';
                                        	}else if(row.dutyCode == 'C'){
                                        		return '乘务';
                                        	}else if(row.dutyCode == 'A'){
                                        		return '保卫';
                                        	}else{
                                        		return '其他';
                                        	}
                                        }
                                    },
                                    {
                                        field : 'ruleType',
                                        title : '类别' ,
                                        formatter : function(value,row,index){
                                        	if(row.ruleType == 'Hard'){
                                        		return '硬规则';
                                        	}else if(row.ruleType == 'Waring'){
                                        		return '告警规则';
                                        	}else if(row.ruleType == 'Soft'){
                                        		return '软规则';
                                        	}else{
                                        		return '其他';
                                        	}
                                        }
                                    },
                                    
                                    {
                                        field : 'ruleCode',
                                        title : '规则编码'
                                    },
                                    {
                                        field : 'ruleContent',
                                        title : '规则说明'
                                    },
                                    {
                                        field : 'ruleScore',
                                        title : '规则得分'
                                    },
                                     {
                                        field : 'isEnabled',
                                        title : '是否可用' ,
                                        formatter : function(value,row,index){
                                        	if(row.isEnabled == '1'){
                                        		return '可用';
                                        	}else{
                                        		return '<font color="red">不可用</font>';
                                        	}
                                        }
                                    },
                                   
                                    {
                                        title : '操作',
                                        align : 'center',
                                        visible : isShowOperation(),
                                        formatter:function(value,row,index){
                                          if(row.isEnabled == '1'){
                                            return [
                                                '<a class="btn btn-sm btn-info '+p_edit+'" href="#" title="编辑" onclick="edit('+row.ruleId+')">',
                                                     '<i class="glyphicon glyphicon-edit"></i>',
                                                '</a>&nbsp;&nbsp;',
                                                '<a class="btn btn-sm btn-warning '+p_edit+'" href="#" title="禁用" onclick="disable('+row.ruleId+')">',
                                                     '<i class="glyphicon glyphicon-off"></i>',
                                                '</a>&nbsp;&nbsp;'
                                                /*  ,
                                                '<a class="btn btn-sm btn-danger '+p_delete+'" href="#" title="删除" onclick="remove('+row.ruleId+')">',
                                                     '<i class="glyphicon glyphicon-remove"></i>',
                                                '</a>&nbsp;&nbsp;'
                                                 */
                                                ].join('');
                                           }else{
                                           	  return [
                                           	     '<a class="btn btn-sm btn-info '+p_edit+'" href="#" title="编辑" onclick="edit('+row.ruleId+')">',
                                                     '<i class="glyphicon glyphicon-edit"></i>',
                                                '</a>&nbsp;&nbsp;',
                                                '<a class="btn btn-sm btn-success '+p_edit+'" href="#" title="启动" onclick="able('+row.ruleId+')">',
                                                     '<i class="glyphicon glyphicon-ok"></i>',
                                                '</a>&nbsp;&nbsp;',
                                                ].join('');
                                           }
                                        }
                                    } ]
                        })
        }

        //是否有权限显示 '操作' 列
        function isShowOperation(){
            return (p_edit != 'hidden' || p_delete != 'hidden');
        }

        //刷新
        function reload(){
            $("#exampleTable").bootstrapTable('refresh');
        }

        //增加
        function add() {
            layer.open({
                type : 2,
                title : '新增',
                maxmin : true,
                shadeClose : false, // 点击遮罩关闭层
                area : [ '40%', '520px' ],
                content : prefix + '/add'
            });
        }

        //编辑
        function edit(ruleId) {
            layer.open({
                type : 2,
                title : '编辑',
                maxmin : true,
                shadeClose : false, // 点击遮罩关闭层
                area : [ '800px', '520px' ],
                content : prefix + '/edit?ruleId=' + ruleId
            });
        }

        //查看
        function view(ruleId) {
            layer.open({
                type : 2,
                title : '查看',
                maxmin : true,
                shadeClose : false, // 点击遮罩关闭层
                area : [ '40%', '520px' ],
                content : prefix + '/view?ruleId=' + ruleId
            });
        }

        //删除
        function remove(ruleId) {
            layer.confirm('确定要删除选中的记录？', {
                btn : [ '确定', '取消' ]
            }, function() {
                $.ajax({
                    url : prefix+"/delete",
                    type : "post",
                    data : {
                        'ruleId' : ruleId
                    },
                    success : function(r) {
                        if (r.code==0) {
                            layer.msg(r.msg);
                            reload();
                        }else{
                            layer.msg(r.msg);
                        }
                    }
                });
            })
        }
        
         //禁用
        function disable(ruleId) {
            layer.confirm('确定要禁用选中的记录？', {
                btn : [ '确定', '取消' ]
            }, function() {
                $.ajax({
                    url : prefix+"/disable",
                    type : "post",
                    data : {
                        'ruleId' : ruleId
                    },
                    success : function(r) {
                        if (r.code==0) {
                            layer.msg(r.msg);
                            reload();
                        }else{
                            layer.msg(r.msg);
                        }
                    }
                });
            })
        }


		 //启用
        function able(ruleId) {
            layer.confirm('确定要启用选中的记录？', {
                btn : [ '确定', '取消' ]
            }, function() {
                $.ajax({
                    url : prefix+"/able",
                    type : "post",
                    data : {
                        'ruleId' : ruleId
                    },
                    success : function(r) {
                        if (r.code==0) {
                            layer.msg(r.msg);
                            reload();
                        }else{
                            layer.msg(r.msg);
                        }
                    }
                });
            })
        }
        
</script>
</body>
</html>